var jsonList = {};
var page = 1;
var rows = 10;
$(function (){ 
    //修改频道跳转
    $(document).on("click",".list_xiu",function (){
        var isS = $(this).attr("pstate");
        var pid = $(this).attr("pdid");
        if (eval(isS)==true){
            window.location.href = "./pin_xiu_xjzdy.html?id="+pid;
        }else{
            window.location.href = "./pin_xiu_xjpt.html?id=" + pid;
        }
    })
    //删除频道
    $(".dis").on("click", function () {
        var numCount = 0;
        var ids = '';
        $(".arc_isc").each(function (index, key) {
            if ($(this).prop("checked") == true) {
                numCount++;
                ids = ids + $(this).attr("oid") + ',';
            }
        })
        ids = ids.substring(0, ids.length - 1);
        //console.log(ids, 555);
        if (numCount == 1) {
            //进行下一步
            zeroModal.confirm("确定要删除该频道吗？", function () {
                //置顶确认请求数据
                $.ajax({
                    url: baseNews + "/api/data/channel/remove?ids=" + ids,
                    type: "get",
                    data: {},
                    success: function (res) {
                        console.log(res, 333)
                        if (res.code == 0) {
                            location.reload();
                        } else {
                            zeroModal.alert(res.message);
                        }
                    }
                })
            })
        } else {
            zeroModal.alert('请选择一条频道删除');
        }
    })
    
})

getList();
function getList() {
    var result = JSON.stringify(jsonList);
    $.ajax({
        url: baseNews + "/api/data/channel/list?page=" + page + "&rows=" + rows,
        type: "post",
        headers: { 'Content-Type': 'application/json' },
        dataType: "json",
        data: result,
        success: function (res) {
            console.log(res, 666);
            if (res.code == 0) {
                var result = res.data;
                var list = result.list;
                console.log(list, 9999)
                var html = "";
                $("#page").paging({
                    pageNo: page,
                    totalPage: result.totalpage,
                    totalSize: result.totals,
                    callback: function (num) {
                        page = num;
                        getList();
                    }
                }) 
                $(".user_list").empty();
                $(list).each(function (index, key) {
                   
                    html += `<tr>
                        <td>  <input type="checkbox" class="arc_isc" oid="${key.id}"/></td>
                        <td>${key.id}</td>
                        <td>${key.cname}</td>
                        <td>${key.csort}</td>
                        <td>${key.reveal?"是":"否"}</td>
                        <td>${key.diy ? "是" : "否"}</td>
                        <td>${key.article}</td>
                        <td>${key.special}</td>
                        <td><span style="cursor: pointer;" class="list_xiu" pstate="${key.diy}" pdid="${key.id}">修改</span></td>
                    </tr>`;
                })
                $(".user_list").append(html);
            }
        }

    })
    //分页
}